package org.phmanago.gui;

import java.awt.Component;
import java.awt.SystemColor;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import org.phmanago.core.Node;
import org.phmanago.utils.FileNode;

class ImageCellRenderer implements ListCellRenderer {

	//private boolean focused = false;
	private JLabel renderer;

	public ImageCellRenderer () {
		renderer = new JLabel();
		renderer.setOpaque (true);
	}

	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		if (value == null) {
			renderer.setText("");
			renderer.setIcon(null);
		} else {
			FileNode x = (FileNode) value;
			renderer.setText(x.get_filename());
			renderer.setIcon(x.get_img());
			renderer.setHorizontalAlignment(JLabel.CENTER);
			renderer.setVerticalTextPosition(JLabel.BOTTOM);
			renderer.setHorizontalTextPosition(JLabel.CENTER);
			renderer.setToolTipText("Size: " + x.get_size());
		}
		renderer.setBackground (isSelected ?
				SystemColor.textHighlight :
					SystemColor.WHITE);
		renderer.setForeground (isSelected ?
				SystemColor.textHighlightText :
					SystemColor.textText);
		return renderer;
	}
}
